package com.snakegame.repository;

import com.snakegame.entity.GameRecord;
import com.snakegame.entity.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;
import org.springframework.data.domain.Pageable;

import java.util.List;

@Repository
public interface GameRecordRepository extends JpaRepository<GameRecord, Long> {
    
    List<GameRecord> findByUserOrderByCreatedAtDesc(User user);
    
    List<GameRecord> findTop10ByOrderByScoreDesc();
    
    @Query("SELECT gr FROM GameRecord gr WHERE gr.user = :user ORDER BY gr.score DESC")
    List<GameRecord> findBestScoresByUser(@Param("user") User user);
    
    //@Query("SELECT gr FROM GameRecord gr WHERE gr.user = :user ORDER BY gr.createdAt DESC")
    //List<GameRecord> findRecentGamesByUser(@Param("user") User user, int limit);
    @Query("SELECT gr FROM GameRecord gr WHERE gr.user = :user ORDER BY gr.createdAt DESC")
    List<GameRecord> findRecentGamesByUser(@Param("user") User user, Pageable pageable);
}
